home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 17
/
CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso
/
CUCD
/
Online
/
News
/
Thor
/
HD-Install
/
thor25_arexx.lha
/
OptConf.thor
< prev
next >
Wrap
Text File
|
1997-04-29
|
14KB
|
473 lines
/* $VER: OptConf V1.10 (27.04.97) Shaun Downend.
* <shaund@amiganut.demon.co.uk>
* Optimise a conference in a BBS.
*
*/
/* Optional configuration items */
repackxpk = 1 /* during optimisation XPK packed conferences are unpacked.
* set this to 1 to repack, or 0 to not repack.
*/
/* End configuration */
scriptver = subword(sourceline(1), 4,1)
scriptinfo = 'OptConf.thor 'scriptver' © Shaun Downend.'
/*!~ "Bit numbers for message flags" */
MDB_READ = 0 /* Message is read. */
MDB_REPLIED = 1 /* Message is replied. */
MDB_PRIVATE = 2 /* Message is private. */
MDB_TO_USER = 3 /* Message is to the user. */
MDB_FROM_USER = 4 /* Message is from the user. */
MDB_DELETED = 5 /* Message is deleted. */
MDB_UNRECOVERABLE = 6 /* Message is can not be undeleted. */
MDB_KEEP = 7 /* Keep message. Message will not be deleted during conference packing. */
MDB_TO_ALL = 8 /* Message is to all. (has no reciever) */
MDB_XPK_TEXT = 9 /* Message text is Xpk'ed. (Private flag) */
MDB_MARKED = 10 /* Message is marked. */
MDB_URGENT = 11 /* Message is urgent. */
MDB_IMPORTANT = 12 /* Message is important. */
MDB_SUPERMARKED = 13 /* Message will not be unmarked as long as this flag is set. */
CDF_NOT_ON_BBS = '00008000'x /* This conference is not on the bbs. */
CDB_NO_XPK_METHOD = 13 /* Don't use any xpk method. */
BDB_NO_XPK_METHOD = 4 /* Don't use any xpk method. */
GCB_NO_XPK_METHOD = 3 /* Don't use any xpk method. */
/*~!*/
options results
options failat 31
signal on syntax
signal on halt
signal on break_c
signal on failure
/*!~ "Open Thor and BBSREAD ARexx ports" */
p=' '||address()||' '||show('P',,)
if pos(' THOR.',p)>0 then
thorport=word(substr(p,pos(' THOR.',p)+1),1)
else
do
say ('Thor has to be running to use this script!')
exit(0)
end
if ~show('p', 'BBSREAD') then
do
address command
'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
'WaitForPort BBSREAD'
if rc ~= 0 then call errmsg('Couldn''t open BBSRead''s ARexx port.')
end
address(thorport)
'VERSION STEM 'version
fullver = subword(version.THOR, 1, 1)
version.thorver = substr(fullver, 1, index(fullver, '.') - 1)
version.thorrev = compress(substr(fullver, index(fullver, '.') + 1), 'ß')
thorversion = version.thorver || '.' || version.thorrev
if thorversion < 2.5 then call errmsg('You need at least Thor 2.5 to run this script!')
/*~!*/
/*!~ "Get list of conference(s) to optimise" */
address(thorport)
'currentsystem' CURRENT
if(rc = 1) then call errmsg('CURRENTSYSTEM failed: No current system')
if(rc = 30) then call errmsg('CURRENTSYSTEM failed: 'THOR.LASTERROR)
address BBSREAD 'getconflist bbsname "'CURRENT.BBSNAME'" stem' CONFLIST
if(rc = 5) then call errmsg('GETCONFLIST failed: BBS not found')
if(rc ~= 0) then call errmsg('GETCONFLIST failed: 'BBSREAD.LASTERROR)
'requestlist instem' CONFLIST 'outstem' SELECTED 'multiselect dragselect title "Select conference(s) to optimise:"'
if(rc = 5) then exit
if(rc ~= 0) then call errmsg('REQUESTLIST failed: 'THOR.LASTERROR)
'lockgui'
address(BBSREAD)
drop CONFDATA.
drop BBSDATA.
drop GLOBDATA.
/* Get System and Global XPK settings */
'getbbsdata bbsname "'CURRENT.BBSNAME'" stem' BBSDATA
if(rc = 5) then call errmsg('GETBBSDATA failed: BBS name not found')
if(rc = 30) then call errmsg('GETBBSDATA failed: 'BBSREAD.LASTERROR)
'getglobaldata stem' GLOBDATA
if(rc = 30) then call errmsg('GETGLOBALDATA failed: 'BBSREAD.LASTERROR)
ptotal = 0
longest = 0
/* Work out information for progress indicator */
do i = 1 to SELECTED.COUNT
'getconfdata bbsname "'CURRENT.BBSNAME'" confname' '"'SELECTED.i'" stem' CONFDATA
if(rc = 7) then call errmsg('GETCONFDATA failed: Conference not found')
if(rc ~= 0) then call errmsg('GETCONFDATA failed: 'BBSREAD.LASTERROR)
/* find the longest conference name to fix width of progress indicator */
if length(SELECTED.i) > longest then longest = length(SELECTED.i)
/* find out if the conference is xpk packed, if so then this requires another step */
if CONFDATA.XPKMETHOD ~= '' then xpk = 10000
else
do
if bittst(CONFDATA.FLAGS,CDB_NO_XPK_METHOD) then xpk = 0
else
do
if BBSDATA.XPKMETHOD ~= '' then xpk = 10000
else
do
if bittst(BBSDATA.FLAGS,BDB_NO_XPK_METHOD) then xpk = 0
else
do
if GLOBDATA.XPKMETHOD ~= '' then xpk = 10000
else
do
if bittst(GLOBDATA.FLAGS,GCB_NO_XPK_METHOD) then xpk = 0
end
end
end
end
end
/* total of progress indicator is xpk + create conf (10000) + copy msgs (10000)
* + pack conf (10000) + delete msgs (10000) + delete conf (10000).
* 10000 is used (a large value) to reduce inaccuracies on division later on.
*/
ptotal = ptotal + xpk + 60000
end
longest = length('Copying messages in ') + longest + length('to ') + longest + length('.temp')
/* open and fix progress indicator width */
call oprog(scriptinfo,ptotal,center('...Starting OptConf.thor...Initialising script...',longest,' '))
pcurrent = 0
'bufmode copyback' /* Turn on copyback mode */
/*~!*/
/*!~ "Main loop" */
do n = 1 to SELECTED.COUNT
conference = SELECTED.n
tempconf = conference'.temp'
call getmsginfo(conference) /* get msg numbers for selected conference */
xpkpack = 0
/* is conference xpk packed? */
if CONFDATA.XPKMETHOD ~= '' then xpkpack = 1
else
do
if bittst(CONFDATA.FLAGS,CDB_NO_XPK_METHOD) then xpkpack = 0
else
do
if BBSDATA.XPKMETHOD ~= '' then xpkpack = 1
else
do
if bittst(BBSDATA.FLAGS,BDB_NO_XPK_METHOD) then xpkpack = 0
else
do
if GLOBDATA.XPKMETHOD ~= '' then xpkpack = 1
else
do
if bittst(GLOBDATA.FLAGS,GCB_NO_XPK_METHOD) then xpkpack = 0
end
end
end
end
end
call uprog(window,pcurrent,'Creating temporary conference 'tempconf'...')
pcurrent = pcurrent + 10000
/* create temporary conference */
'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" set' c2x(CDF_NOT_ON_BBS)
if(rc ~= 0) then call errmsg('CONFIGCONF failed: 'BBSREAD.LASTERROR)
call copyconf(conference,tempconf) /* copy msgs from orig conf to temp conf */
/*!~ "Delete messages in original conference" */
call uprog(window,pcurrent,'Deleting messages in 'conference)
pstart = pcurrent
if (CONFDATA.LASTMSG - CONFDATA.FIRSTMSG) ~= 0 then /* is conference empty? */
do
pinc = 10000 % (CONFDATA.LASTMSG - CONFDATA.FIRSTMSG)
do i= CONFDATA.FIRSTMSG to CONFDATA.LASTMSG
drop OLDMSGDATA.
if (pcurrent // 10 = 0) then call uprog(window,pcurrent)
pcurrent = pcurrent + pinc
'readbrmessage "'CURRENT.BBSNAME'"' '"'conference'"' i 'datastem' OLDMSGDATA
if(rc ~= 0) then call bbsreaderr
if ~bittst(OLDMSGDATA.FLAGS,MDB_DELETED) then /* is message already deleted? */
do
'updatebrmessage "'CURRENT.BBSNAME'"' '"'conference'"' i 'setdeleted'
if(rc ~= 0) then call bbsreaderr
end
end
pcurrent = pstart + 10000 /* adjust to fix any inaccuracies in previous division :-) */
end
else /* conference is empty so skip */
do
pinc = pstart + 10000
call uprog(window,pcurrent)
end
/*~!*/
/*!~ "Pack original conference" */
call uprog(window,pcurrent,'Clearing 'conference'...')
pcurrent = pcurrent + 10000
'packdatafile "'CURRENT.BBSNAME'" confname' '"'conference'"'
if(rc ~= 0) then call errmsg('PACKDATAFILE failed: 'BBSREAD.LASTERROR)
/*~!*/
call getmsginfo(tempconf) /* get msg numbers for temp conf */
call copyconf(tempconf,conference) /* copy msgs from temp conf to orig conf */
/*!~ "Delete temporary conference" */
call uprog(window,pcurrent,'Deleting 'tempconf'...')
pcurrent = pcurrent + 10000
'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" deleteconf'
if(rc ~= 0) then call errmsg('CONFIGCONF failed: 'BBSREAD.LASTERROR)
/*~!*/
/*!~ "Repack XPK packed conference" */
if repackxpk = 1 then
do
if xpkpack = 1 then
do /* If conference was xpk-packed then pack it */
call uprog(window,pcurrent,'XPK Packing 'conference'...')
pcurrent = pcurrent + 10000
address(BBSREAD)
'packdatafile "'CURRENT.BBSNAME'" confname' '"'conference'"'
if(rc ~= 0) then call errmsg('PACKDATAFILE failed: 'BBSREAD.LASTERROR)
end
end
/*~!*/
end
call uprog(window,pcurrent,'Complete.')
do i = 1 to 600
end
pcurrent = pcurrent + 10000
/*!~ "Notify completion, update conf window, cleanup" */
address(thorport)
'updateconfwindow'
'unlockgui'
address(bbsread)
'bufmode endcopyback'
call cprog(window)
address(thorport)
'requestnotify "OptConf.thor complete!"' '" _OK "'
if(rc = 30) then say THOR.LASTERROR
exit
/*~!*/
/*~!*/
/*!~ "Copy all messages from one conference to another conference " */
copyconf:
parse arg fromconf,toconf
call uprog(window,pcurrent,'Copying messages in 'fromconf 'to 'toconf)
pstart = pcurrent
if (CONFDATA.LASTMSG - CONFDATA.FIRSTMSG) ~= 0 then /* is conference empty? */
do
pinc = 10000 % (CONFDATA.LASTMSG - CONFDATA.FIRSTMSG)
do i= CONFDATA.FIRSTMSG to CONFDATA.LASTMSG
drop MSGTAGS.
drop MSGDATA.
if (pcurrent // 10 = 0) then call uprog(window,pcurrent)
pcurrent = pcurrent + pinc
'readbrmessage "'CURRENT.BBSNAME'"' '"'fromconf'"' i 'headstem' MSGTAGS 'textstem' MSGTAGS 'datastem' MSGDATA
if(rc ~= 0) then call bbsreaderr
if ~bittst(MSGDATA.FLAGS,MDB_DELETED) | ~bittst(MSGDATA.FLAGS,MDB_UNRECOVERABLE) then
do
exargs = ''
if ~bittst(MSGDATA.FLAGS,MDB_MARKED) then exargs = exargs || ' DONTMARKMESSAGE'
if bittst(MSGDATA.FLAGS,MDB_PRIVATE) then exargs = exargs || ' PRIVATE'
if bittst(MSGDATA.FLAGS,MDB_READ) then exargs = exargs || ' READ'
if bittst(MSGDATA.FLAGS,MDB_URGENT) then exargs = exargs || ' URGENT'
if bittst(MSGDATA.FLAGS,MDB_IMPORTANT) then exargs = exargs || ' IMPORTANT'
'writebrmessage "'CURRENT.BBSNAME'"' '"'toconf'" stem' MSGTAGS exargs
if(rc ~= 0) then call bbsreaderr
msgnr = result
exargs = ''
if bittst(MSGDATA.FLAGS,MDB_KEEP) then exargs = exargs || ' SETKEEP'
if bittst(MSGDATA.FLAGS,MDB_SUPERMARKED) then exargs = exargs || ' SETSUPERUNREAD'
if bittst(MSGDATA.FLAGS,MDB_REPLIED) then exargs = exargs || ' SETREPLIED'
if MSGDATA.HAZELEVEL ~= 0 then exargs = exargs || ' HAZELEVEL ' || MSGDATA.HAZELEVEL
if exargs ~= '' then 'updatebrmessage "'CURRENT.BBSNAME'"' '"'toconf'"' msgnr exargs
if(rc ~= 0) then call bbsreaderr
end
/*
else say 'Message deleted or unrecoverable'
*/
end
pcurrent = pstart + 10000 /* adjust for any inaccuracies in previous division :-) */
end
else /* conference is empty so skip it */
do
pinc = pstart + 10000
call uprog(window,pcurrent)
end
return
/*~!*/
/*!~ "Get message numbers for a conference" */
getmsginfo:
parse arg conf
drop CONFDATA.
'getconfdata bbsname "'CURRENT.BBSNAME'" confname' '"'conf'" stem' CONFDATA
if(rc = 7) then call errmsg('GETCONFDATA failed: Conference not found')
if(rc ~= 0) then call errmsg('GETCONFDATA failed: 'BBSREAD.LASTERROR)
return
/*~!*/
/*!~ "Progress indication" */
/*!~ "Open progress indicator" */
oprog:
parse arg ptitle,ptotal,ptxt
address(thorport)
'openprogress title "'ptitle'" total' ptotal 'pt "'ptxt'"'
if(rc ~= 0) then call errmsg(THOR.LASTERROR,10)
else window = result
return
/*~!*/
/*!~ "Update progress indicator" */
uprog:
parse arg pwindow,pcurrent,ptxt
/*
say 'current 'pcurrent
*/
if ptxt = '' then ptxt = ''
else ptxt = 'pt ' || '"'ptxt'"'
address(thorport)
'updateprogress req' pwindow 'current' pcurrent ptxt
if(rc~=0) then signal cleanup
return(0)
/*~!*/
/*!~ "Close Progress indicator" */
cprog:
parse arg pwindow
address(thorport)
'closeprogress req' pwindow
return
/*~!*/
/*~!*/
/*!~ "Error handling" */
break_c:
call errmsg('User break!')
error:
halt:
failure:
if rc ~= 0 then call errmsg('+++ Line 'sigl' returned 'rc': 'errortext(rc))
cleanup:
address(bbsread)
'bufmode endcopyback'
if window ~= 'WINDOW' then call cprog(window)
address(thorport)
'unlockgui'
exit(0)
errmsg:
parse arg msgtxt
address(thorport)
'requestnotify "'msgtxt'"' '" _OK "'
if(rc = 30) then say THOR.LASTERROR
signal cleanup
return
bbsreaderr:
address(bbsread)
'configconf "'CURRENT.BBSNAME'"' '"'tempconf'" deleteconf'
if(rc ~= 0) then
do
address(thorport)
'requestnotify "CONFIGCONF failed: 'BBSREAD.LASTERROR'\nFailed to delete temporary conference."' '" _OK "'
end
address(thorport)
'requestnotify "BBSRead Error: 'BBSREAD.LASTERROR'\nThere appears to be a problem with the database.\nPlease repair the database before running this script.\nSystem : 'CURRENT.BBSNAME'\nConference: 'fromconf'\nMessage no: 'i'."' '" _OK "'
signal cleanup
return
/*~!*/